package com.zfzs.post.modules.post.rest;

import com.zfzs.post.aop.log.Log;
import com.zfzs.post.common.bean.ResponseResult;
import com.zfzs.post.modules.post.domain.TerminalType;
import com.zfzs.post.modules.post.service.TerminalTypeService;
import com.zfzs.post.modules.post.service.dto.TerminalTypeQueryCriteria;
import com.zfzs.post.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 终端类型
 *
 * @author wq
 * @date 2019-11-12
 */
@RestController
@RequestMapping("terminalType")
public class TerminalTypeController {

    @Autowired
    private TerminalTypeService postTerminalTypeService;

    /**
     * 列表查询
     *
     * @param criteria
     * @param pageable
     * @return
     */
    @Log("列表查询")
    @GetMapping(value = "/list")
    public ResponseResult getPostTerminalTypes(TerminalTypeQueryCriteria criteria, Pageable pageable) {
        return ResponseResult.ok(postTerminalTypeService.queryAll(criteria, pageable));
    }

    /**
     * 新增
     *
     * @param resources
     * @return
     */
    @Log("新增")
    @PostMapping(value = "/add")
    public ResponseResult create(@Validated @RequestBody TerminalType resources) {
        return ResponseResult.ok(postTerminalTypeService.create(resources));
    }

    /**
     * 修改
     *
     * @param resources
     * @return
     */
    @Log("修改")
    @PutMapping(value = "/update")
    public ResponseResult update(@Validated @RequestBody TerminalType resources) {
        postTerminalTypeService.update(resources);
        return ResponseResult.ok();
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Log("删除")
    @DeleteMapping(value = "/delete/{id}")
    public ResponseResult delete(@PathVariable Long id) {
        postTerminalTypeService.delete(id);
        return ResponseResult.ok();
    }

    /**
     * 获取所有终端类型
     */
    @Log("获取所有终端类型")
    @GetMapping(value = "/getTerminalList")
    public ResponseResult getTerminalList() {
        Long channelId = SecurityUtils.getUserId();
        List<TerminalType> list = postTerminalTypeService.findByChannelId(channelId);
        return ResponseResult.ok(list);
    }
}